Char field


In [1]:
from konfoo import Index, Byteorder, Char

Item

Item type of the field class.


In [2]:
Char.item_type


Out[2]:
ItemClass.Char = 43

Checks if the field class is a bit field.


In [3]:
Char.is_bit()


Out[3]:
False

Checks if the field class is a boolean field.


In [4]:
Char.is_bool()


Out[4]:
False

Checks if the field class is a decimal number field.


In [5]:
Char.is_decimal()


Out[5]:
True

Checks if the field class is a floating point number field.


In [6]:
Char.is_float()


Out[6]:
False

Checks if the field class is a pointer field.


In [7]:
Char.is_pointer()


Out[7]:
False

Checks if the field class is a stream field.


In [8]:
Char.is_stream()


Out[8]:
False

Checks if the field class is a string field.


In [9]:
Char.is_stream()


Out[9]:
False

Field


In [10]:
char = Char(align_to=None)

In [11]:
char = Char(0)

Field view


In [12]:
char


Out[12]:
Char(index=Index(byte=0, bit=0, address=0, base_address=0, update=False), alignment=Alignment(byte_size=1, bit_offset=0), bit_size=8, value='\x00')

In [13]:
str(char)


Out[13]:
'Char(Index(byte=0, bit=0, address=0, base_address=0, update=False), Alignment(byte_size=1, bit_offset=0), 8, \x00)'

In [14]:
repr(char)


Out[14]:
"Char(index=Index(byte=0, bit=0, address=0, base_address=0, update=False), alignment=Alignment(byte_size=1, bit_offset=0), bit_size=8, value='\\x00')"

Field name


In [15]:
char.name


Out[15]:
'Char'

Field index


In [16]:
char.index


Out[16]:
Index(byte=0, bit=0, address=0, base_address=0, update=False)

Byte index of the field within the byte stream.


In [17]:
char.index.byte


Out[17]:
0

Bit offset relative to the byte index of the field within the byte stream.


In [18]:
char.index.bit


Out[18]:
0

Absolute address of the field within the data source.


In [19]:
char.index.address


Out[19]:
0

Base address of the byte stream within the data source.


In [20]:
char.index.base_address


Out[20]:
0

Indexes the field and returns the index after the field.


In [21]:
char.index_field(index=Index())


Out[21]:
Index(byte=1, bit=0, address=1, base_address=0, update=False)

Field alignment


In [22]:
char.alignment


Out[22]:
Alignment(byte_size=1, bit_offset=0)

Byte size of the field group which the field is aligned to.


In [23]:
char.alignment.byte_size


Out[23]:
1

Bit offset of the field within its aligned field group.


In [24]:
char.alignment.bit_offset


Out[24]:
0

Field size


In [25]:
char.bit_size


Out[25]:
8

Field byte order


In [26]:
char.byte_order


Out[26]:
Byteorder.auto = 'auto'

In [27]:
char.byte_order.value


Out[27]:
'auto'

In [28]:
char.byte_order.name


Out[28]:
'auto'

In [29]:
char.byte_order = 'auto'

In [30]:
char.byte_order = Byteorder.auto

Field value

Checks if the decimal field is signed or unsigned.


In [31]:
char.signed


Out[31]:
False

Maximal decimal field value.


In [32]:
char.max()


Out[32]:
255

Minimal decimal field value.


In [33]:
char.min()


Out[33]:
0

Returns the char field value as as an unicode string character.


In [34]:
char.value


Out[34]:
'\x00'

Returns the decimal field value aligned to its field group as a number of bytes.


In [35]:
bytes(char)


Out[35]:
b'\x00'

In [36]:
bytes(char).hex()


Out[36]:
'00'

Returns the decimal field value as an integer number.


In [37]:
int(char)


Out[37]:
0

Returns the decimal field value as an floating point number.


In [38]:
float(char)


Out[38]:
0.0

Returns the decimal field value as a lowercase hexadecimal string prefixed with 0x.


In [39]:
hex(char)


Out[39]:
'0x0'

Returns the decimal field value as a binary string prefixed with 0b.


In [40]:
bin(char)


Out[40]:
'0b0'

Returns the decimal field value as an octal string prefixed with 0o.


In [41]:
oct(char)


Out[41]:
'0o0'

Returns the decimal field value as a boolean value.


In [42]:
bool(char)


Out[42]:
False

Returns the decimal field value as a signed integer number.


In [43]:
char.as_signed()


Out[43]:
0

Returns the decimal field value as an unsigned integer number.


In [44]:
char.as_unsigned()


Out[44]:
0

Field metadata

Returns the meatadata of the field as an ordered dictionary.


In [45]:
char.describe()


Out[45]:
OrderedDict([('address', 0),
             ('alignment', [1, 0]),
             ('class', 'Char'),
             ('index', [0, 0]),
             ('max', 255),
             ('min', 0),
             ('name', 'Char'),
             ('order', 'auto'),
             ('signed', False),
             ('size', 8),
             ('type', 'Field'),
             ('value', '\x00')])

Deserialize


In [46]:
char.deserialize(bytes.fromhex('41'))


Out[46]:
Index(byte=1, bit=0, address=1, base_address=0, update=False)

In [47]:
char.value


Out[47]:
'A'

In [48]:
bytes(char)


Out[48]:
b'A'

In [49]:
bytes(char).hex()


Out[49]:
'41'

In [50]:
int(char)


Out[50]:
65

In [51]:
float(char)


Out[51]:
65.0

In [52]:
hex(char)


Out[52]:
'0x41'

In [53]:
bin(char)


Out[53]:
'0b1000001'

In [54]:
oct(char)


Out[54]:
'0o101'

In [55]:
bool(char)


Out[55]:
True

In [56]:
ord(char.value)


Out[56]:
65

In [57]:
chr(int(char))


Out[57]:
'A'

Serialize


In [58]:
buffer = bytearray()

In [59]:
char.value = 65

In [60]:
char.value = 65.0

In [61]:
char.value = 0x41

In [62]:
char.value = 0b1000001

In [63]:
char.value = 0o101

In [64]:
char.value = True

In [65]:
char.value = ord('A')

In [66]:
char.value = 'A'

In [67]:
char.serialize(buffer, byte_order='little')


Out[67]:
Index(byte=1, bit=0, address=1, base_address=0, update=False)

In [68]:
buffer.hex()


Out[68]:
'41'

In [69]:
bytes(char).hex()


Out[69]:
'41'

In [ ]: